import 'package:flutter/material.dart';
import 'package:flutter_base/statemanagement_demo/models/goods_entity.dart';

class GoodsItem extends StatelessWidget {
  const GoodsItem(this.goodsEntity, {super.key});

  final GoodsEntity goodsEntity;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.grey[100],
        borderRadius: BorderRadius.circular(8.0),
      ),
      padding: const EdgeInsets.all(5.0),
      margin: const EdgeInsets.all(5.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          _buildImage('商品图片'),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                _buildTitle(context, goodsEntity.name),
                _buildTitle(context, '￥${goodsEntity.price}'),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildImage(String imageUrl) {
    return SizedBox(
      width: 80.0,
      height: 80.0,
      child: Text(imageUrl),
    );
  }

  Widget _buildTitle(BuildContext context, String text) {
    return Container(
      height: 30.0,
      margin: const EdgeInsets.only(left: 10.0),
      alignment: Alignment.centerLeft,
      child: Text(
        text,
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
        style: Theme.of(context).textTheme.titleMedium,
      ),
    );
  }
}
